package com.java.controller;

import com.java.pojo.*;
import com.java.service.StudentFunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * description:描述
 * author:作者
 * time:2020/11/23 23:44
 */
@Controller
public class StudentFunctionController {

    @Autowired
    private StudentFunctionService studentFunctionService;


    /**
     * 通过微信号查看学生个人信息
     * @param studentWxid
     * @return
     */
    @RequestMapping("/getStudentInfoByWxid.do")
    public @ResponseBody Student_info getStudentInfoByWxid(String studentWxid) throws Exception {
        if(studentWxid.equals("")){
            throw new Exception();
        }
        return studentFunctionService.findStudentInfoByWxid(studentWxid);
    }


    /**
     * 修改学生个人信息
     * @param studentInfo
     * @return
     */
    @RequestMapping("/updateStudentInfo.do")
    public @ResponseBody boolean setStudentInfo(@RequestBody Map<String,Object> studentInfo){
        Student_info student_info = new Student_info();
        student_info.setStudentWxid((String) studentInfo.get("studentWxid"));
        student_info.setStudentName((String) studentInfo.get("studentName"));
        student_info.setImage_path((String) studentInfo.get("image_path"));
        student_info.setSno((String) studentInfo.get("sno"));
        student_info.setStudentClass((String) studentInfo.get("studentClass"));

        return studentFunctionService.updateStudentInfo(student_info);
    }

    /**
     * 通过微信号查看学生课程信息
     * @param studentWxid
     * @return
     */
    @RequestMapping("/getCourseInfoByWxid.do")
    public @ResponseBody List<CourseList> getCourseInfoByWxid(String studentWxid) throws Exception {
        if(studentWxid.equals("")){
            throw new Exception();
        }
        return studentFunctionService.findStudentCourseByWxid(studentWxid);
    }

    /**
     * 获取所有可选课程
     * @param
     * @return
     */
    @RequestMapping("/getAllCourse.do")
    public @ResponseBody List<CourseList> getAllCourse() throws Exception {
        return studentFunctionService.findAllCourse();
    }

    /**
     * 通过课程号查看课程详细信息
     * @param courseId
     * @return
     */
    @RequestMapping("/getCourseDetail.do")
    public @ResponseBody Course_detail getCourseDetailByWxid(String courseId) throws Exception {

        return studentFunctionService.findCourseDetailByWxid(courseId);
    }

    /**
     * 添加个人课程
     * @param addCourseInfo
     * @return
     */
    @RequestMapping("/addStudentCourse.do")
    public @ResponseBody boolean addStudentCourse(@RequestBody Map<String,String> addCourseInfo){

        String studentWxid=addCourseInfo.get("studentWxid");
        String courseId=addCourseInfo.get("courseId");
        if("".equals(studentWxid)||"".equals(courseId)){
            return false;
        }

        return studentFunctionService.addStudentCourse(studentWxid,courseId);
    }

    /**
     * 删除个人课程
     * @param addCourseInfo
     * @return
     */
    @RequestMapping("/deleteStudentCourse.do")
    public @ResponseBody boolean deleteStudentCourse(@RequestBody Map<String,String> addCourseInfo){

        String studentWxid=addCourseInfo.get("studentWxid");
        String courseId=addCourseInfo.get("courseId");

        return studentFunctionService.deleteStudentCourse(studentWxid,courseId);
    }

    /**
     * 签到成功false
     * @param checkInfo
     * @return
     */
    @RequestMapping("/checkSuccess.do")
    public @ResponseBody int checkSuccess(@RequestBody Map<String,Object> checkInfo){
        CheckInfo checkClassInfo = new CheckInfo();
        checkClassInfo.setStudentId((String) checkInfo.get("studentWxid"));
        checkClassInfo.setCourseId((String) checkInfo.get("courseId"));
        checkClassInfo.setCourseNum((String) checkInfo.get("courseNum"));
        checkClassInfo.setCheckTime((String) checkInfo.get("checkTime"));

        return studentFunctionService.checkSuccess(checkClassInfo);
    }


}
